package jdbc.task1;

import java.sql.Date;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Scanner;

/*
2：在控制台输入一个学生的全部信息，保存到数据库，
注意日期的处理(Statement)
 */
public class Task3 extends DbUtil_1 {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        Task3 t = new Task3();

        System.out.print("输入学号：");
        int stuno = input.nextInt();
        System.out.print("输入姓名：");
        String sname = input.next();
        System.out.print("输入性别：");
        String sex = input.next();
        System.out.print("输入电话：");
        String telephone = input.next();
        System.out.print("输入qq：");
        String qq = input.next();
        System.out.print("输入微信：");
        String wechat = input.next();
        System.out.print("输入年级：");
        int gradeid = input.nextInt();
        System.out.print("输入入学日期（格式：yyyy-MM-dd）：");
        String enterdate1 = input.next();
        System.out.print("输入来自城市：");
        String fromcity = input.next();
        System.out.print("输入生日（格式：yyyy-MM-dd）：");
        String birthday1 = input.next();
        System.out.print("输入出生地址：");
        String address = input.next();
        System.out.print("输入密码：");
        String pass = input.next();

        DateFormat sim = new SimpleDateFormat("yyyy-MM-dd");
        Date enterdate = null;
        Date birthday = null;
        try {
            enterdate = new Date(sim.parse(enterdate1).getTime());
            birthday = new Date(sim.parse(birthday1).getTime());
        } catch (ParseException e) {
            e.printStackTrace();
        }


        String sql = "insert into s_student values(?,?,?,?,?,?,?,?,?,?,?,?,?)";
        Object[] s = {stuno, sname, sex, telephone, qq, wechat, gradeid, enterdate, fromcity, birthday, address, pass, "DEFAULT"};
        t.executeSql(sql, s);

    }
}
